let nums = [1,3,5,6,8,9]
let target = 6

const binarySearch = (nums,target)=>{
    let left =0
    let right = nums.length-1
    while(left<=right){
        let mid = left + Math.floor((right-left)/2)
        if(nums[mid] === target){
            return mid
        }else if(nums[mid]<target){
            left = mid+1
        }else{
            right = mid-1
        }
    }
    //没有找到则返回-1呗。时间复杂度为O(logn)
    return -1
}
console.log(binarySearch(nums,target));
